import paho.mqtt.client as mqtt

def on_connect(client, userdata, flags, rc):
    print("Connected with result code: " + str(rc))

def on_message(client, userdata, msg):
    print(msg.topic + " " + str(msg.payload))

def int16arr_to_bytearray(x):
    result = []
    for item in x:
        result.append(item & 0xff)
        result.append(item >> 8)

    return bytearray(result)

greeoff = [8950, 4450,\
                650, 550, 650, 1600, 700, 500, 700, 500, 650, 1650, 650, 550, 650, 550, 650, 550,\
                650, 550, 650, 500, 700, 500, 650, 1650, 650, 550, 650, 550, 650, 550, 650, 550,\
                650, 550, 650, 500, 700, 500, 650, 550, 650, 550, 650, 1650, 650, 550, 650, 550,\
                650, 500, 700, 500, 700, 500, 650, 550, 650, 1650, 650, 550, 650, 1600, 700, 500,\
                650, 550, 650, 1650, 650, 550,\
                650, 19750,\
                700, 500, 700, 500, 700, 500, 650, 550, 650, 550, 650, 550, 650, 550, 650, 550,\
                650, 550, 650, 550, 650, 500, 700, 500, 650, 550, 650, 550, 650, 550, 650, 550,\
                650, 550, 650, 550, 650, 550, 650, 500, 700, 500, 700, 500, 650, 550, 650, 550,\
                650, 550, 650, 550, 650, 550, 650, 550, 650, 500, 700, 500, 700, 1600, 650, 550,\
                650, 39600, 8900, 4450,\
                650, 550, 650, 1600, 700, 550, 650, 500, 700, 1600, 650, 550, 650, 550, 650, 550,\
                650, 550, 650, 550, 650, 500, 700, 1600, 650, 550, 650, 550, 650, 550, 650, 550,\
                650, 550, 650, 550, 650, 500, 700, 500, 700, 500, 650, 1650, 650, 550, 650, 550,\
                650, 550, 650, 550, 650, 500, 700, 500, 650, 1650, 650, 1650, 650, 1600, 700, 500,\
                650, 550, 650, 1650, 650, 550,\
                650, 19750,\
                700, 500, 700, 500, 700, 500, 650, 550, 650, 550, 650, 550, 650, 550, 650, 550,\
                650, 550, 650, 550, 650, 500, 700, 500, 650, 550, 650, 550, 650, 550, 650, 550,\
                650, 550, 650, 550, 650, 550, 650, 500, 700, 1600, 650, 550, 650, 550, 650, 550,\
                650, 550, 650, 550, 650, 550, 650, 500, 700, 1600, 650, 550, 650, 1650, 650, 550,\
                650]

client = mqtt.Client(client_id="python-abc")
client.on_connect = on_connect
client.on_message = on_message
client.connect('119.91.90.201', 1883, 600) # 600为keepalive的时间间隔
# client.publish('inTopic', "HelloWorld", qos=0)

client.publish('home/wol', payload=bytearray([0x00, 0x01, 0x02, 0x03, 0x04, 0x05]), qos=0)


